#define  _CRT_SECURE_NO_WARNINGS 1

#include "Heap.h"

void TestHeapSort()
{
	int n = 50;
	int* arr = (int*)malloc(n * sizeof(int));
	if (arr == NULL)
	{
		perror("malloc fail");
		exit(-1);
	}

	for (int i = 0; i < n; ++i)
	{
		arr[i] = rand() % 101;
	}

	PrintArray(arr, n);
	HeapSort(arr, n);
	PrintArray(arr, n);

}

void TestHeap()
{
	Heap Hp;
	HeapInit(&Hp);
	HeapPush(&Hp, 5);
	HeapPush(&Hp, 8);
	HeapPush(&Hp, 44);
	HeapPush(&Hp, 0);
	HeapPush(&Hp, 6);
	HeapPush(&Hp, 2);
	printf("HeapTop: %d\n", HeapTop(&Hp));
	PrintArray(Hp.arr, Hp.size);
	HeapPop(&Hp);
	HeapPop(&Hp);
	printf("HeapTop: %d\n", HeapTop(&Hp));
	PrintArray(Hp.arr, Hp.size);
	HeapPush(&Hp, 100);
	HeapPush(&Hp, 69);
	HeapPush(&Hp, 78);
	HeapPush(&Hp, 66);
	printf("HeapTop: %d\n", HeapTop(&Hp));
	PrintArray(Hp.arr, Hp.size);
	while (!HeapEmpty(&Hp))
	{
		printf("%d ", HeapTop(&Hp));
		HeapPop(&Hp);
	}
	printf("\n");

	HeapDestory(&Hp);
}

int main()
{
	srand((unsigned int)time(NULL));
	//TestHeapSort();
	TestHeap();

	return 0;
}